import { ElMessage } from 'element-plus';

export type MessageType = 'success' | 'warning' | 'info' | 'error';

export interface MessageService {
  success: (message: string, duration?: number) => void;
  warning: (message: string, duration?: number) => void;
  info: (message: string, duration?: number) => void;
  error: (message: string, duration?: number) => void;
}

// 定义消息服务的实现
const messageService: MessageService = {
  success(message: string, duration: number = 3000) {
    ElMessage({
      message,
      type: 'success',
      duration,
    });
  },
  warning(message: string, duration: number = 3000) {
    ElMessage({
      message,
      type: 'warning',
      duration,
    });
  },
  info(message: string, duration: number = 3000) {
    ElMessage({
      message,
      type: 'info',
      duration,
    });
  },
  error(message: string, duration: number = 3000) {
    ElMessage({
      message,
      type: 'error',
      duration,
    });
  },
};

export default messageService;
